<template>
  <div class="com">
    <!-- 头部 -->
    <header>
      <div class="left">
        <p>{{ score.overall }}</p>
        <p>综合评价</p>
        <p>高于周边商家76.9%</p>
      </div>
      <div class="right">
        <p>
          服务态度
          <van-rate v-model="score.service" readonly :size="12" gutter="1" />
          <span>{{ score.service }}</span>
        </p>
        <p>
          菜品评价
          <van-rate v-model="score.food" readonly :size="12" gutter="1" />
          <span>{{ score.food }}</span>
        </p>
        <p>
          送达时间
          <span class="minute">{{ score.time }}分钟</span>
        </p>
      </div>
    </header>
    <!-- 中间评论分类 -->
    <ul class="Comment">
      <li
        v-for="(item, i) in tags"
        :key="item._id"
        :class="{ blue: target == i }"
        @click="target = i"
      >
        {{ item.name }}({{ item.count }})
      </li>
    </ul>
    <!-- 评论 -->
    <ul v-for="(item, i) in 5" :key="i">
      <li class="PersonComment" v-for="item in comment" :key="item._id">
        <img
          src="https://fuss10.elemecdn.com/1/5f/6cf782b0c9cd5ca8daa7f76ab05aejpeg.jpeg"
          alt=""
        />
        <div class="item">
          <div class="item-top">
            <div>
              <p>4**************6</p>
              <p class="tag">
                <van-rate
                  v-model="item.rating_star"
                  readonly
                  :size="12"
                  gutter="2"
                />
                {{ item.time_spent_desc }}
              </p>
            </div>
            <span>{{ item.rated_at }}</span>
          </div>
          <div class="imgbox">
            <img
              style="width: 76px; height: 76px"
              alt=""
              v-for="tag in item.item_ratings"
              :key="tag.food_id + Math.random()"
              :src="'https://fuss10.elemecdn.com/' + tag.image_hash"
            />
          </div>
          <div>
            <span
              class="bottom-tag"
              v-for="tag in item.item_ratings"
              :key="tag.food_id"
              >{{ tag.food_name }}</span
            >
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { scores, ratings, tags } from "@/api/goods-details.js";
export default {
  data() {
    return {
      //头部评分数据
      score: {
        service: 5,
        food: 5,
        time: 30,
        overall: 4.8,
      },
      //底部评论数据
      comment: [],
      //评论分类
      tags: [],
      target: 0,
    };
  },
  created() {
    let id = this.$route.query.restaurant_id;
    // 头部评分获取数据
    scores(id).then((res) => {
      // console.log(75, res);
      this.score.service = parseFloat(res.data.service_score.toFixed(1));
      this.score.food = parseFloat(res.data.food_score.toFixed(1));
      this.score.time = res.data.deliver_time;
      this.score.overall = parseFloat(res.data.overall_score.toFixed(1));
    });

    tags(id).then((res) => {
      this.tags = res.data;
      console.log(105, res.data);
    });
    //底部评论数据
    ratings(id).then((res) => {
      this.comment = res.data;
    });
  },
  //请求评论数据
};
</script>

<style lang="less" scoped>
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.com {
  height: 550px;
  overflow: auto;
  position: relative;
  background-color: #fff;
}
header {
  display: flex;
  height: 120px;
  border: 1px solid #f5f5f5;
  color: #6d6d6d;
  padding: 20px 13px;
  .left {
    width: 167px;
    display: flex;
    flex-direction: column;
    align-items: center;
    p {
      &:nth-child(1) {
        font-size: 31px;
        color: coral;
      }
      &:nth-child(2) {
        font-size: 16px;
        color: #666;
      }
      &:nth-child(3) {
        font-size: 12px;
      }
    }
  }
  .right {
    flex: 2;
    p {
      position: relative;
      height: 25px;
      span {
        position: absolute;
        top: 5px;
        right: 39px;
        font-size: 16px;
        color: orange;
      }
    }
    .van-rate--readonly {
      position: absolute;
      left: 80px;
      bottom: 3px;
    }
    .minute {
      position: absolute;
      left: 80px;
      bottom: 3px;
      font-size: 12px;
    }
  }
}

.Comment {
  display: flex;
  flex-wrap: wrap;
  padding: 13px;
  li {
    font-size: 16px;
    padding: 8px;
    border-radius: 10%;
    background-color: #ebf5ff;
    color: #6d7885;
    border-radius: 10px;
    margin: 0 10px 5px 0;
    &.blue {
      background-color: #3190e8;
      color: #fff;
    }
  }
}

.PersonComment {
  display: flex;
  padding: 15px 13px;
  border: 2px solid #f5f5f5;
  img {
    width: 38px;
    height: 38px;
    margin-right: 20px;
    border-radius: 50%;
  }
  .item {
    width: 100%;
    // height: 173px;
    .item-top {
      display: flex;
      justify-content: space-between;
    }
    .tag {
      margin-top: 5px;
      font-size: 14px;
    }
  }
  .van-tag--success {
    width: 55px;
    height: 30px;
    text-align: center;
    justify-content: center;
  }
  .imgbox {
    margin: 5px 0 10px;
  }
  .bottom-tag {
    display: inline-block;
    color: #999;
    border: 1px solid #ebebeb;
    margin-right: 10px;
    width: 60px;
    height: 27px;
    line-height: 27px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>
